GBML manual / 3D

Speed: why 30 frames

What the 3D view costs the console, why a 3D game is happy at 30 frames a second, and what makes it faster.

What a frame is worth

The console shows 60 pictures a second. A game finishes its work for a frame, then waits for the next refresh. If the work takes less than one refresh (16.7 milliseconds), the game runs at 60 frames a second. If it takes more than one but less than two, it simply waits for the second refresh and runs at 30 frames a second, perfectly steady. Only work that takes more than two refreshes drops lower.

30 frames a second is fine for a 3D game. It is what 3D games ran at on this kind of console, and a steady 30 looks and plays better than a 60 that sometimes slips to 45.

What the view costs

Measured on a release build of a room 24 by 24 tiles, with the view alone (nothing else drawing), as a share of one 60 frames a second refresh:

What the camera is doingAverageWorst frameFrames over one refresh
Turning in the middle of the room59%77%0%
Walking and turning, bumping into walls64%112%6%
Standing 1.5 tiles from a wall (the most rows to draw)92%95%0%

So the view by itself fits in a 60 frames a second refresh, and the rest of the game (your objects, a HUD, sounds) has what is left, with the whole second refresh as a cushion: a frame that takes up to twice as long still runs a steady 30.

With things in the view

Seven things (enemies, items) added to the same room, drawn every frame:

What is going onAverageWorst frameFrames over one refresh
7 things 3 to 5 tiles away, camera turning78%111%9%
7 things, walking and turning70%82%0%
7 big things 1.5 to 2 tiles away, camera turning85%118%12%
7 big things, camera 1.5 tiles from a wall80%83%0%

A thing costs only the pixels it covers, and only in the screen columns where no wall is in front of it, so a thing far away costs almost nothing and a thing right in front of the camera costs the most. Seven big things close up are still well inside the two refreshes a steady 30 frames a second allows (the worst frame was 118% of one refresh), so there is room for the rest of the game. The view draws at most 24 things a frame.

Where the time goes

Most of the time is spent writing the picture: 120 columns by 160 rows of 2-pixel-wide dots, about 19,000 writes. A wall that is close covers many rows, so a close wall costs more than a far one. The floor and ceiling cost almost nothing: the console only repaints the part of a column that was a wall last time and is not now.

Making it faster

The build does the rest ahead of time: it cuts the wall pictures into columns, and works out the tables for angles, distances and heights, so the console never calculates them while the game runs.

See also: 3D viewview3d_heightMaking 3D walls